package com.jlcloud.core.boot.config;

import jakarta.servlet.DispatcherType;
import lombok.AllArgsConstructor;
import com.jlcloud.core.boot.request.JlCloudRequestFilter;
import com.jlcloud.core.boot.request.RequestProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;

/**
 * 过滤器配置类
 *
 * @author By: JlCloud <br>
 * @Package: com.jlcloud <br>
 * @CreateTime: 2024-12-03 21:45 <br>
 * @Copyright: 2021 www.jilianjituan.com Inc. All rights reserved. <br>
 * @Caution 注意：本内容仅限于冀联人力集团内部传阅，禁止外泄以及用于其他的商业目的 <br>
 */
@AutoConfiguration
@AllArgsConstructor
@EnableConfigurationProperties({RequestProperties.class})
public class JlCloudRequestConfiguration {

	private final RequestProperties requestProperties;

	/**
	 * 全局过滤器
	 */
	@Bean
	public FilterRegistrationBean<JlCloudRequestFilter> jlcloudFilterRegistration() {
		FilterRegistrationBean<JlCloudRequestFilter> registration = new FilterRegistrationBean<>();
		registration.setDispatcherTypes(DispatcherType.REQUEST);
		registration.setFilter(new JlCloudRequestFilter(requestProperties));
		registration.addUrlPatterns("/*");
		registration.setName("jlcloudRequestFilter");
		registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
		return registration;
	}
}
